package com.wmy.teachersystem;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.teachersystem.R;
import com.example.teachersystem.StudentActivity;


public class ClassListViewAdapter extends BaseAdapter {

	private List<Classes> students ;
	private Context context;
	
	public ClassListViewAdapter(List<Classes> students, Context context) {
		super();
		this.students = students;
		this.context = context;
	}

	@Override
	public int getCount() {
		return students == null ? 0 : students.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = LayoutInflater.from(context).inflate(R.layout.item_class_list, null);
		TextView tv_name = (TextView) v.findViewById(R.id.item_student_list_name);
		TextView tv_studentId = (TextView) v.findViewById(R.id.item_student_list_studentId);
		
		Classes s = students.get(position);
		
		tv_name.setText(s.getName());
		tv_studentId.setText(s.getStudentId());
		
		v.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, StudentActivity.class);
				context.startActivity(intent);
				
			}
		});
		
		return v;
	}
}
